<?php

/***************************************************************\
* FILE:		sys/pages/location.inc
* SECTION:	pages > activities
* FUNCTION:	location and address management
* USES:	
* INCLUDES:	/sys/locationfunctions.inc	
* PRODUCES:	
* LAUNCHES:	
\***************************************************************/

include_once("sys/locationfunctions.inc");
				
/**
 * adds extra access checks, dependent on page state
 */
function page_inc_check_access() {
	check_access("READ");
	check_access("ADMIN");
}

/**
 * appropriate page action interpretations
 */
function page_inc_execute_action($action) {
	global $PAGE;
	switch($action) {
		case "add_address":
		
			$PAGE['content']['title'] = "Een adres toevoegen";
		
			if ($_POST['submitted']) {
				$id = location_add_address($_POST);
				if ($id > 0)
					die("adres #$id ingevoerd");
			}
			$PAGE['content']['form'] = location_form_address();
			break;
			
		case "edit_address":
		
			if (!$_POST['address_id']) {
				$PAGE['content']['title'] = "Adressen wijzigen";
				$inputs = array();
				$kv = location_list_address();
				$inputs[] = form_input_select("Adres", "address_id", $kv['keys'], $kv['values'], "kies een adres om te wijzigen", "", "document.addressform.submit()");
				$PAGE['content']['form'] = form_create("addressform", $inputs);
			} else {
				$PAGE['content']['title'] = "Adres #{$_POST['address_id']} wijzigen";
			
				if ($_POST['submitted']) {
					$id = location_edit_address($_POST);
					if ($id > 0)
						die("adres #$id aangepast");
				}
				$PAGE['content']['form'] = location_form_address(location_fetch_address($_POST['address_id']));
			}
			break;

		default:
			add_alert('onbekende actie');
			break;
	}
}

/**
 * execute page logic
 */
function page_inc_execute() {
	global $PAGE;
	$CONTENT = array();
	
	add_action('add_address', 'url-action', 'add_address');
	add_action('edit_address', 'url-action', 'edit_address');
	
}


/**
 * dress up page content using skin stuff
 */
function page_inc_dress() {
	global $PAGE;
	if ($PAGE['content']['form'])
		print_form($PAGE['content']['form']);
}

?>